//
//  ViewController.m
//  28-UIViewAnimation
//
//  Created by dllo on 16/8/22.
//  Copyright © 2016年 ZHW. All rights reserved.
//

#import "ViewController.h"
#import "UIView+ChangeFrame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    _animationView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_animationView];
    
    /*
     
    // 1 UIView Animation
    // 开始动画设置
    // 参数1: 动画标识
    // 参数2: 上下文
    [UIView beginAnimations:nil context:NULL];
    
     UIViewAnimationCurveEaseInOut // 开始和结束缓慢
     UIViewAnimationCurveEaseIn  // 开始缓慢
     UIViewAnimationCurveEaseOut // 结束缓慢
     UIViewAnimationCurveLinear // 匀速
    
    // 2> 设置动画曲线
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    // 3> 设置动画持续时间
    [UIView setAnimationDuration:5];
    // 4> 动画延时
//    [UIView setAnimationDelay:10];
//    [UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:10]];
    // 持续次数
    [UIView setAnimationRepeatCount:2.5];
    // 5> 设置往返动画 一个来回算一次
    [UIView setAnimationRepeatAutoreverses:YES];
    // 6> 忽略动画过程
    [UIView setAnimationsEnabled:YES];
    // 7> 动画的改变
    _animationView.z_x = 100;
    // 8> 动画的代理 不签订代理 代理方法不执行(默认为不签订)
    [UIView setAnimationDelegate:self];
    // 将要开始
    [UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
    // 已经结束
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    // 9> 结束动画设置, 执行该动画
    [UIView commitAnimations];
    
    */
  
//    // 2 UIViewAnimationBlock
//    // 参数1: 持续时间 参数2: block需要执行的动画效果
//    [UIView animateWithDuration:5 animations:^{
//        _animationView.z_width = 200;
//    }];
//    
//    // 参数3: 完成 需要执行的操作
//    [UIView animateWithDuration:3 animations:^{
//        _animationView.z_width = 200;
//    } completion:^(BOOL finished) {
//        NSLog(@"动画完成后的操作");
//    }];
    // options: 按位枚举 重复,往返动画等设置
    [UIView animateWithDuration:4 delay:2 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
        _animationView.z_width = 200;
    } completion:^(BOOL finished) {
        NSLog(@"动画完成后的操作");
    }];
}

- (void)animationWillStart:(NSString *)animationID context:(void *)context {
    NSLog(@"动画将要开始");
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    NSLog(@"end");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
